/**
 * @author 徐楠
 * @date 2022/2/20 10:13
 * @version 1.0
 */

package com.xunan.likou;

public class RemoveDuplicatesFromOrderedArrays {
    public static void main(String[] args) {
        int[] nums = {1, 1, 2};
        //int[] nums = {0, 0, 1, 1, 1, 2, 2, 3, 3, 4};
        //返回正确数组的长度
        int result = removeDuplicates(nums);
        System.out.println(result);
        System.out.println("---");
        for (int j = 0; j < nums.length; j++) {
            System.out.println(nums[j]);
        }
    }

    public static int removeDuplicates(int[] nums) {
        int length = nums.length;
        int left = 0;
        for (int right = 0; right < length; right++) {
            if (nums[right] != nums[left]) {
                left++;
                int temp = nums[left];
                nums[left] = nums[right];
                nums[right] = temp;

            }
        }
        return ++left;

    }
}
